package com.attendance.www.hr.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.attendance.www.hr.beans.AttachmentBean;
import com.attendance.www.hr.beans.UserEmployeeBean;
import com.attendance.www.hr.constant.AppConstant;
import com.attendance.www.hr.exception.ResultFaultException;
import com.attendance.www.hr.service.ICodeImportService;
import com.zhangkongli.frame.core.ResultMap;


/**
 * 编码信息导入
 * @author CulQi
 *
 */
@Controller
@RequestMapping("/codeImport")
public class CodeImportController {
	
	@Resource
	private ICodeImportService codeImportService;

	/**
	 * 模板下载
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/getCodeURL.do", method = {RequestMethod.POST,RequestMethod.GET})
	@ResponseBody 
	public Object getCodeURL(HttpServletRequest request){
		return AppConstant.TEMPLATE_RESOURCE+"/基本信息导入模板.xlsx";
	}

	/**
	 * 编码信息导入接口
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/importCode.do", method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public Object importCode(HttpServletRequest request ,@RequestBody AttachmentBean attachmentBean) throws Exception {
		
		if (attachmentBean.getAttachmentId()==null || attachmentBean.getType()==null||attachmentBean.getFromDate()==null) {
			throw new ResultFaultException("0_00001");
		}
		
	    UserEmployeeBean userEmployee = (UserEmployeeBean)request.getSession().getAttribute(AppConstant.SESSIONUSER);
	
		//第二步导入编码信息数据
		List<String> successList=codeImportService.importCode(attachmentBean, userEmployee.getUserId());

		return ResultMap.success(successList);
	}
}
